package com.stx.bms.web;

import com.stx.bms.dao.BlogDAO;
import com.stx.bms.dao.BlogDAOImpl;
import com.stx.bms.entity.Blog;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/blog-list")
public class BlogListServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        System.out.println("出生了。。。");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("服务。。。");
        //获取参数

        //存取数据库的数据
        BlogDAO dao = new BlogDAOImpl();
        List<Blog> blogList = dao.viewAll();

        //暂存数据到request中（后续在jsp中获取出来显示）
        request.setAttribute("bList", blogList);

        //页面跳转（请求转发、重定向）
        request.getRequestDispatcher("list.jsp").forward(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("死亡了。。。");
    }
}
